#include "restoredialog.h"
#include "ui_restoredialog.h"

#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>
#include <QStringList>

RestoreDialog::RestoreDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RestoreDialog)
{
    ui->setupUi(this);
    move(0,0);
#ifdef BUILD_ARM
    setGeometry(70,128,460,595);
#endif

    //设置不可编辑
    ui->hmiPro_lineEdit->setFocusPolicy(Qt::NoFocus);
    ui->controllerPro_lineEdit->setFocusPolicy(Qt::NoFocus);
}

RestoreDialog::~RestoreDialog()
{
    delete ui;
}

void RestoreDialog::changeLangauge()
{
    ui->retranslateUi(this);
}

void RestoreDialog::on_returnBtn_clicked()
{
    this->hide();
}

void RestoreDialog::on_browseHmi_Btn_clicked()
{
    QFileDialog dialog(this,"");
    dialog.resize(580,400);
    dialog.setAcceptMode(QFileDialog::AcceptOpen);
    dialog.setNameFilter("ZIP(*.zip)");
    //dialog.setFileMode(QFileDialog::Directory);
    dialog.setDirectory("/");

    QStringList files = dialog.selectedFiles();
    if(!files.isEmpty())
    {
        if(dialog.exec() == QFileDialog::Accepted)
        {
            qDebug()<<"ok";
            QStringList name = dialog.selectedFiles();
            QString line = name.join("");
            ui->hmiPro_lineEdit->setText(line);
        }
        else
        {
            qDebug()<<"close";
        }
    }
}

void RestoreDialog::on_browseCont_Btn_clicked()
{
    QFileDialog dialog(this,"");
    dialog.resize(580,400);
    dialog.setAcceptMode(QFileDialog::AcceptOpen);
    dialog.setNameFilter("ZIP(*.zip)");
    //dialog.setFileMode(QFileDialog::Directory);
    dialog.setDirectory("/");

    QStringList files = dialog.selectedFiles();
    if(!files.isEmpty())
    {
        if(dialog.exec() == QFileDialog::Accepted)
        {
            qDebug()<<"ok";
            QStringList name = dialog.selectedFiles();
            QString line = name.join("");
            ui->controllerPro_lineEdit->setText(line);
        }
        else
        {
            qDebug()<<"close";
        }
    }
}

void RestoreDialog::on_updateHmi_Btn_clicked()
{
    restoreCheckDialog->showAndSetTitle(HMI_UPDATE,ui->hmiPro_lineEdit->text());
}

void RestoreDialog::on_updateCont_Btn_clicked()
{
    restoreCheckDialog->showAndSetTitle(CTRL_UPDATE,ui->controllerPro_lineEdit->text());
}

void RestoreDialog::on_restoreHmi_Btn_clicked()
{
    restoreCheckDialog->showAndSetTitle(HMI_RESTORE,"");
}

void RestoreDialog::on_restoreController_Btn_clicked()
{   
    restoreCheckDialog->showAndSetTitle(CTRL_RESTORE,"");
}
